package c.x.jy.dao.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import c.x.jy.dao.dto.TeacherEntityDto;
import c.x.jy.dao.entity.TeacherEntity;

/**
 * 老师申请及信息表
 * 
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-24 10:16:30
 */
@Mapper
public interface TeacherDao extends BaseMapper<TeacherEntity> {
    @Select("SELECT   t.*,  m.name as membername,m.nickname as membernickName, m.headimgurl as headimgurl ,(SELECT min(s.discount_price) from t_teacher_service s force index(teacher_id) WHERE  s.teacher_id=t.id ) as minprice  FROM `t_teacher` t left join t_member m on m.id=t.member_id     ${ew.customSqlSegment} ")
	IPage<TeacherEntityDto> dtoPage(IPage<TeacherEntity> page, @Param(Constants.WRAPPER) QueryWrapper<TeacherEntity> query);

    @Select("SELECT DISTINCT  t.*,  m.name as membername,m.nickname as membernickName, m.headimgurl as headimgurl  FROM `t_teacher` t left join t_member m on m.id=t.member_id left join t_teacher_service  ts on ts.teacher_id=t.id     ${ew.customSqlSegment} ")
    IPage<TeacherEntityDto> selectlist(IPage<TeacherEntity> page, @Param(Constants.WRAPPER) QueryWrapper<TeacherEntity> query);
    @Select("SELECT   t.*, m.name as membername,m.nickname as membernickName, m.headimgurl as headimgurl  FROM `t_teacher` t left join t_member m on m.id=t.member_id  where t.id=${id}")
    TeacherEntityDto selectDtoById(Long id);
    @Select("SELECT   t.*,m.name as membername,m.nickname as membernickName, m.headimgurl as headimgurl  FROM `t_teacher` t left join t_member m on m.id=t.member_id   ${ew.customSqlSegment}")
    List<TeacherEntityDto> selectListDto( @Param(Constants.WRAPPER) QueryWrapper<TeacherEntity> query);

    @Select("SELECT DISTINCT  t.*,m.name as membername,m.nickname as membernickName, m.headimgurl as headimgurl  FROM (`t_teacher_service` ts left join `t_member` m on m.id=ts.member_id) LEFT JOIN `t_teacher` t on t.member_id=ts.member_id ${ew.customSqlSegment}")
    List<TeacherEntityDto> selectTeacherInfoByServiceId(  @Param(Constants.WRAPPER) QueryWrapper<TeacherEntity> query);
//    TeacherEntityDto selectListDto(QueryWrapper<TeacherEntity> query);
 
    
    @Select("select * from t_teacher t LEFT JOIN t_teacher_config tc on tc.teacher_id =t.id where tc.join_quick_ask =1")
	List<TeacherEntity> selectTeachersByJoinQuickAsk();
}

